﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Inspinia_MVC5.Code
{
    //session过滤器，不允许用户离线访问
    public class SessionTimeOutFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var ctx = filterContext.HttpContext;
            if (ctx.Session != null)
            {
                object session = ctx.Session["username"];
                if (session == null)
                {
                    //filterContext.Result = new JsonResult
                    //{
                    //    Data = new { status = "1" },
                    //    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    //};
                    filterContext.HttpContext.Response.Redirect("/Login/LoginEn");
                }
            }
            else
            {
                //filterContext.Result = new JsonResult
                //{
                //    Data = new { status = "1" },
                //    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                //};
                filterContext.HttpContext.Response.Redirect("/Login/LoginEn");
            }
            base.OnActionExecuting(filterContext);
        }
    }
}